import { permissionConstant } from "@/constants/permission.constant";
import { useAppSelector } from "@/hooks/useReduxHook";
import { ReactNode } from "react";
export type PBtnType ={
  children?: Array<ReactNode>|ReactNode;
  code?: string;
};
export default function PermissionBtn(props: PBtnType) {
  const userInfo = useAppSelector((state) => state.permission.userInfo);
  const { children, code } = props;
  const { permissions, roles } = userInfo;
  if (roles && roles.includes("admin")) return <>{children}</>;
  if(!code) return(<></>)
  const pCode = permissionConstant[code]
  if (pCode && permissions && permissions.includes(pCode)) return(<>{children}</>);
  return (<></>);
}
